package com.springboot.mybatis;

import com.alibaba.druid.pool.DruidDataSource;
import com.springboot.mybatis.entity.Book;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/*
 *DATE:2025/7/9
 */
public class TestJDBCBook {
    public static void main(String[] args) throws SQLException {
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setUrl("jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=utf-8");
        druidDataSource.setUsername("root");
        druidDataSource.setPassword("123456");
        //获得数据库连接
        Connection connection = druidDataSource.getConnection();
        PreparedStatement pst = connection.prepareStatement("select * from book");
        ResultSet rs = pst.executeQuery();
        List<Book> list = new ArrayList<>();
        while (rs.next())
        {
            list.add(new Book(rs.getInt(1),
                    rs.getString(2),
                    rs.getString(3)));
        }
        System.out.println( list);
    }
}
